package org.giovanolli.mumi.dao.impl;

import org.apache.commons.lang.StringUtils;
import org.giovanolli.mumi.dao.TitleDao;
import org.giovanolli.mumi.entities.Title;
import org.giovanolli.mumi.entities.filter.EntityFilter;
import org.giovanolli.mumi.entities.filter.TitleFilter;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

// TODO: Auto-generated Javadoc
/**
 * The Class TitleDaoImpl.
 */
@Repository("titleDao")
public class TitleDaoImpl extends HibernateDao<Title> implements TitleDao {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.giovanolli.mumi.dao.impl.BaseDaoImpl#fillCriteria(org.giovanolli. mumi.entities.filter.EntityFilter, org.hibernate.criterion.DetachedCriteria)
	 */
	@Override
	protected DetachedCriteria fillCriteria(EntityFilter<Title> filter, DetachedCriteria criteria) {
		final TitleFilter entityFilter = (TitleFilter) filter;

		if (filter != null) {
			if (StringUtils.isNotBlank(entityFilter.getName())) {
				criteria.add(Restrictions.ilike("name", entityFilter.getName(), MatchMode.ANYWHERE));
			}
		}
		return criteria;
	}

}
